package com.sykj.bsc.zjj.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.bsc.rwl.commons.ServerResponse;
import com.sykj.bsc.rwl.po.SysMenu;
import com.sykj.bsc.zjj.bean.Bis_custom_user;
import com.sykj.bsc.zjj.bean.Bis_shop_post;
import com.sykj.bsc.zjj.bean.Bis_shop_user;
import com.sykj.bsc.zjj.service.Bis_shop_userService1;

/**
 * 前台
 * 员工管理
 * @author Lenovo G50-80
 *
 */
@Controller
@RequestMapping("proltal/zjj1")
public class Bis_shop_userController1 {
	@Autowired
	private Bis_shop_userService1 bsus1;
	
	/**
	 * 查询所有
	 * Bis_shop_user
	 * 店铺用户信息表
	 * @param map
	 * @param bsu
	 * @return
	 */
	@RequestMapping("selectBis_shop_user1")
	public String selectBis_shop_user1(Map<String, Object> map,Model model,Bis_shop_user bsu,@RequestParam(value = "page", defaultValue = "1") Integer page,HttpSession session) {
		PageHelper.startPage(page,2);
		//session
		String shop_id=(String)session.getAttribute("shop_id");
		bsu.setShop_id(shop_id);
		//bsu.setShop_id("10000001");
		
		//定值
		if(bsu!=null) getbis_custom_user(model, bsu);
		
		List<Map> list = this.bsus1.selectBis_shop_user1(bsu);
		//map.put("list", list);
		PageInfo<Map> info = new PageInfo<>(list);
		map.put("info", info);
		/**
		 * 店铺职位信息表
		 */
		List<Bis_shop_post> list3 = this.bsus1.seListBis_shop_post1();
		map.put("list3", list3);
		return "foreground/zjj/Employeemanagement";		
	}
	
	/**
	 * 条件查询定值方法
	 * @param model
	 * @param bsu
	 */
	private void  getbis_custom_user(Model model,Bis_shop_user bsu) {
		if (bsu.getAccount()!=null && !bsu.getAccount().equals("")) {
			model.addAttribute("account", bsu.getAccount());
		}
		if (bsu.getUsername()!=null && !bsu.getUsername().equals("")) {
			model.addAttribute("username", bsu.getUsername());
		}
		if (bsu.getPost_code()!=null && !bsu.getPost_code().equals("")) {
			model.addAttribute("post_code", bsu.getPost_code());
		}
		if (bsu.getWork_number()!=null && !bsu.getWork_number().equals("")) {
			model.addAttribute("work_number", bsu.getWork_number());
		}
		if (bsu.getMobile()!=null && !bsu.getMobile().equals("")) {
			model.addAttribute("mobile", bsu.getMobile());
		}
		if (bsu.getEntry_date1()!=null && !bsu.getEntry_date1().equals("")) {
			model.addAttribute("entry_date1", bsu.getEntry_date1());
		}
		if (bsu.getEntry_date2()!=null && !bsu.getEntry_date2().equals("")) {
			model.addAttribute("entry_date2", bsu.getEntry_date2());
		}
	}
	
	/**
	 * 根据ID查询
	 * @param shop_user_id
	 * @param map
	 * @return
	 */
	@RequestMapping("findByIdBis_shop_user1/{shop_user_id}")
	public String findByIdBis_shop_user1(@PathVariable("shop_user_id") String shop_user_id,Bis_shop_user bsu1,Map<String, Object> map,HttpSession session){
		//session
		String shop_id=(String)session.getAttribute("shop_id");
		bsu1.setShop_id(shop_id);
		//bsu1.setShop_id("10000001");
		
		bsu1.setShop_user_id(shop_user_id);
		Bis_shop_user bsu = this.bsus1.findByIdBis_shop_user1(bsu1);
		map.put("bsu", bsu);
		return "foreground/zjj/Employeemanagement1";
	}
	
	@RequestMapping("loginurl")
	public String loginurl() {
		return "foreground/login";
	}
	
	/**
	 * @Title: login   
	 * @Description: 登录  
	 * @param: @param account
	 * @param: @param password
	 * @param: @param session
	 * @param: @return      
	 * @return: ServerResponse<Bis_shop_user>      
	 * @throws
	 */
	@RequestMapping("login")
	public @ResponseBody ServerResponse<Bis_shop_user> login(String account,String password,HttpSession session) {
		ServerResponse<Bis_shop_user> valid=bsus1.find_Bis_shop_user(account, password);
		if(valid.isSuccess()) {
			session.setAttribute("protalUser", valid.getData());
		}
		return valid;
	}
	
	@RequestMapping("loginmenu")
	public String loginmenu(HttpSession session,Model model){
		Bis_shop_user bUser=(Bis_shop_user) session.getAttribute("protalUser");
		String post_code=bUser.getPost_code();
		List<SysMenu> list=bsus1.findUserMenu(post_code);
		model.addAttribute("list", list);
		return "foreground/index";
	}
	
}
